package com.easy;

/**
 * Created by Lxk on 2019/6/7.
 */
public class Solution345 {

    private static final String str = "aeiouAEIOU";

    private boolean isContains(char val){
        for(char each : str.toCharArray()){
            if(each==val){
                return true;
            }
        }
        return false;
    }


    public String reverseVowels(String s) {
        if(s==null){
            return null;
        }
        if("".equals(s)){
            return "";
        }
        char[] arr = s.toCharArray();
        int begin = 0;
        int end = s.length()-1;
        while(true){
            while(begin<=end){
                if(isContains(s.charAt(begin))){
                    break;
                }else{
                    begin++;
                }
            }
            while(end>=begin){
                if(isContains(s.charAt(end))){
                    break;
                }else{
                    end--;
                }
            }
            if(end<=begin){
                break;
            }
            char temp = arr[begin];
            arr[begin] = arr[end];
            arr[end] = temp;
            begin++;
            end--;
        }
        StringBuffer sb = new StringBuffer();
        for(char val : arr){
            sb.append(val);
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        String st = "hello";
        Solution345 solution345 = new Solution345();
        solution345.reverseVowels(st);
    }

}
